import {HttpRequest} from "@/network";
import {ApiConst} from "@/network/config/ApiConst";
import AppConfig from "@/config/AppConfig";

let env = AppConfig.env;
export default class GrayService {
  static async getGrayList() {
    let promise = HttpRequest.get({
      url: ApiConst.gray[env].get.GET_GRAY_LIST,
      env: env
    }).then(res => {
      if (res.err === null) {
        return res.data.data
      }
    }).catch(err => {
      console.error("请求出错。");
      throw err;
    })
    return await promise;
  }

  static async addGray(data) {
    let promise = HttpRequest.post({
      url: ApiConst.gray[env].post.POST_GRAY,
      data,
      env: env
    }).then(res => {
      if (res.err === null) {
        return res.data.data
      }
    }).catch(err => {
      console.error("请求出错。");
      throw err;
    })
    return await promise;
  }
}
